package cn.com.nou.base;

import lombok.Data;

/**
 * 返回数据
 *
 * @author xuao
 */
@Data
public class R {
    private static final long serialVersionUID = 1L;

    private String code;
    private String msg;
    private Object data;

    private R() {
        this.setCode(ResultCode.SUCCESS.getCode());
        this.setMsg(ResultCode.SUCCESS.getMsg());
    }


    public static R ok() {
        return new R();
    }

    public R put(Object data) {
        this.setData(data);
        return this;
    }

    public static R error(ResultCode resultCode) {
        R r = new R();
        r.setCode(resultCode.getCode());
        r.setMsg(resultCode.getMsg());
        return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(ResultCode.FAILED.getCode());
        r.setMsg(ResultCode.FAILED.getMsg());
        return r;
    }

    public static R sysError() {
        R r = new R();
        r.setCode(ResultCode.SYS_ERROR.getCode());
        r.setMsg(ResultCode.SYS_ERROR.getMsg());
        return r;
    }
}
